<?php

use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use Dcat\Admin\Admin;

Admin::routes();

Route::group([
    'prefix'     => config('admin.route.prefix'),
    'namespace'  => config('admin.route.namespace'),
    'middleware' => config('admin.route.middleware'),
], function (Router $router) {

    $router->get('/', 'HomeController@index');
    
    // 自提点管理路由
    // 自提点清单
    $router->get('/pickup', 'PickupPointController@index')->name('admin.pickup.index');
    $router->get('/pickup/create', 'PickupPointController@create')->name('admin.pickup.create');
    $router->get('/pickup/{id}', 'PickupPointController@show')->name('admin.pickup.show');
    $router->get('/pickup/{id}/edit', 'PickupPointController@edit')->name('admin.pickup.edit');
    
    // 申请列表
    $router->get('/pickup-applications', 'PickupApplicationController@index')->name('admin.pickup.applications.index');
    $router->get('/pickup-applications/{id}', 'PickupApplicationController@show')->name('admin.pickup.applications.show');
    $router->get('/pickup-applications/{id}/review', 'PickupApplicationController@review')->name('admin.pickup.applications.review');
    
    // 申请审核 AJAX 路由
    $router->post('/pickup-applications/{id}/approve', 'PickupApplicationController@approve')->name('admin.pickup.applications.approve');
    $router->post('/pickup-applications/{id}/reject', 'PickupApplicationController@reject')->name('admin.pickup.applications.reject');
    
     // 门店申请省市区API接口（必须在参数路由之前）
    $router->post('/store-apply/addresses', 'StoreApplyController@getAddresses')->name('admin.store.apply.addresses');
    
    // 门店申请管理路由
    $router->get('/store-apply', 'StoreApplyController@index')->name('admin.store.apply.index');
    // 门店申请列表API（Vue 列表请求）
    $router->get('/store-apply/list', 'StoreApplyController@list')->name('admin.store.apply.list');
    
   
    // 门店申请详情和审核路由（参数路由放在最后）
    $router->get('/store-apply/{id}', 'StoreApplyController@detail')->name('admin.store.apply.detail');
    $router->get('/store-apply/{id}/review', 'StoreApplyController@review')->name('admin.store.apply.review');
    
    // 门店申请审核 AJAX 路由
    $router->post('/store-apply/{id}/approve', 'StoreApplyController@approve')->name('admin.store.apply.approve');
    $router->post('/store-apply/{id}/reject', 'StoreApplyController@reject')->name('admin.store.apply.reject');
    
    // 门店清单管理路由
    $router->get('/store', 'StoreController@index')->name('admin.store.index');
    // 门店授信额度审核相关路由
    $router->get('/store/quota-audit', 'StoreController@quotaAudit')->name('admin.store.quota-audit');
    $router->post('/store/quota-audit/list', 'StoreController@quotaAuditList')->name('admin.store.quota-audit.list');
    $router->post('/store/quota-audit/{id}/approve', 'StoreController@quotaAuditApprove')->name('admin.store.quota-audit.approve');
    $router->post('/store/quota-audit/{id}/reject', 'StoreController@quotaAuditReject')->name('admin.store.quota-audit.reject');
    // 门店清单列表API（Vue 列表请求）
    $router->get('/store/list', 'StoreController@list')->name('admin.store.list');
    
    // 门店省市区API接口（必须在参数路由之前）
    // $router->get('/store/addresses', 'StoreController@getAddresses')->name('admin.store.addresses');
    // 门店详情更新接口（必须在参数路由之前，避免被 /store/{id} 匹配）
    $router->any('/store/update-detail', 'StoreController@updateDetail')->name('admin.store.update.detail');
    // 搜索店长（必须在参数路由之前，避免被 /store/{id} 匹配）
    $router->get('/store/search-managers', 'StoreController@searchManagers')->name('admin.store.search.managers');
    
    // 门店详情和状态更新路由（参数路由放在最后）
    $router->get('/store/{id}', 'StoreController@detail')->name('admin.store.detail');
    $router->post('/store/update-status', 'StoreController@updateStatus')->name('admin.store.update.status');
    
    // 门店核销员相关API
    $router->get('/store/{id}/clerks', 'StoreController@getClerks')->name('admin.store.clerks');
    $router->post('/store/clerk/update-status', 'StoreController@updateClerkStatus')->name('admin.store.clerk.update.status');
    
    // 门店密码修改API
    $router->post('/store/{id}/update-password', 'StoreController@updatePassword')->name('admin.store.update.password');
    
    // 门店分组相关API
    $router->get('/store/groups', 'StoreController@getGroups')->name('admin.store.groups');
    $router->post('/store/update-group', 'StoreController@updateGroup')->name('admin.store.update.group');
    
    // 置换分组相关API
    $router->post('/stores/switch-groups', 'StoreController@getSwitchGroups')->name('admin.stores.switch.groups');
    $router->get('/stores/groups/{groupId}/properties', 'StoreController@getGroupProperties')->name('admin.stores.group.properties');
    $router->get('/store/{storeId}/switch-groups/{groupId}/relations', 'StoreController@getStoreGroupRelations')->name('admin.store.switch.group.relations');
    $router->post('/store/{storeId}/switch-groups/relations', 'StoreController@updateStoreGroupRelations')->name('admin.store.switch.group.update.relations');
    
    // 提成明细
    $router->get('/pickup-commissions', 'PickupCommissionController@index')->name('admin.pickup.commissions.index');
    $router->get('/pickup-commissions/{id}', 'PickupCommissionController@show')->name('admin.pickup.commissions.show');
    $router->get('/pickup-commissions/settlement', 'PickupCommissionController@settlement')->name('admin.pickup.commissions.settlement');
    
    // 供应商清单
    $router->get('/suppliers', 'SupplierController@index')->name('admin.suppliers.index');
    $router->get('/suppliers/{id}', 'SupplierController@show')->name('admin.suppliers.show');
    
    // 供应商API接口
    $router->get('/api/suppliers/platforms', 'SupplierController@getPlatforms')->name('admin.api.suppliers.platforms');
    $router->get('/api/suppliers/by-platform', 'SupplierController@getSuppliersByPlatform')->name('admin.api.suppliers.by-platform');
    $router->get('/api/suppliers/by-merchant', 'SupplierController@getSuppliersByMerchant')->name('admin.api.suppliers.by-merchant');
    $router->post('/api/suppliers/batch-assign', 'SupplierController@batchAssign')->name('admin.api.suppliers.batch-assign');
    $router->post('/api/suppliers/batch-remove', 'SupplierController@batchRemove')->name('admin.api.suppliers.batch-remove');
    
    // 地址接口 - 省市区联动
    $router->get('/api/address/provinces', 'AddressController@provinces')->name('admin.api.address.provinces');
    $router->get('/api/address/cities/{provinceId}', 'AddressController@cities')->name('admin.api.address.cities');
    $router->get('/api/address/districts/{cityId}', 'AddressController@districts')->name('admin.api.address.districts');
    
    // 自提点API接口
    $router->post('/api/pickup/toggle-status', 'PickupPointController@toggleStatus')->name('admin.api.pickup.toggle-status');

    // 门店分组相关API
    // $router->post('/store/store-categories', 'StoreController@getCategories')->name('admin.store.categories');
    
    //门店商品相关api
    $router->get('/store-goods', 'StoreGoodsController@index')->name('admin.store.goods.index');
    // 商品详情编辑页
    $router->get('/store-goods/detail', 'StoreGoodsController@detailPage')->name('admin.store.goods.detail');
    // 门店商品列表API（查询所有门店的商品）
    $router->post('/store-goods/list', 'StoreGoodsController@goodsList')->name('admin.store.goods.list');
    // 获取商品详情（后台用）
    $router->post('/store-goods/get-detail', 'StoreGoodsController@getDetail')->name('admin.store.goods.get');
    // 批量更新商品（后台用）
    $router->post('/store-goods/batch-update', 'StoreGoodsController@batchUpdate')->name('admin.store.goods.batch.update');
    // 更新单个商品（后台用）
    $router->post('/store-goods/update', 'StoreGoodsController@updateGoods')->name('admin.store.goods.update');
    // 更新商品规格（后台用）
    $router->post('/store-goods/update-specs', 'StoreGoodsController@updateSpecs')->name('admin.store.goods.update.specs');
    
    $router->get('/store-view', 'StoreController@view')->name('admin.store.view');
    $router->post('/store/execute', 'StoreController@execute')->name('admin.store.execute');
    

});
